﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Love2DWindow
{
    /// <summary>
    /// Model 层
    /// </summary>
    public class GameScene : Love.Scene
    {

        private bool _isUpdate = false;
        public float Red = 1;
        public float Green = 0;
        public float Blue = 0;
        public float Left = 0;
        public float Top = 0;
        public float Width = 100;
        public float Height = 100;

        public float BackRed = 0;
        public float BackGreen = 1;
        public float BackBlue = 0;

        public DateTime DateTime;
        public GameScene()
        {

        }

        public override void Load()
        {
            // 重设窗体，以实现重绘，这两步必须要在最开始，其他地方调用不行，我不知道为什么，非常的神奇。
            var mode = Love.Window.GetMode(); Love.Window.SetMode(mode);

            Love.Graphics.SetFont(Love.Graphics.NewFont(36));

        }


        public override void Update(float dt)
        {
            if (_isUpdate)
            {
                DateTime = DateTime.Now;
                base.Update(dt);
            }

        }

        public override void Draw()
        {
            Love.Graphics.SetBackgroundColor(Love.Color.FromRGBA(BackRed, BackGreen, BackBlue, 1));
            Love.Graphics.SetColor(Love.Color.FromRGBA(Red, Green, Blue, 1));
            Love.Graphics.Rectangle(Love.DrawMode.Fill, Left, Top, Width, Height);
            Love.Graphics.SetColor(Love.Color.Black);
            Love.Graphics.Print(DateTime.ToString());
        }



        public void Run()
        {
            _isUpdate = true;

        }

        public void Pause()
        {
            _isUpdate = false;
        }

        public void Switch()
        {
            if (_isUpdate)
                Pause();
            else
                Run();
        }

    }
}
